package com.eshop.service.Impl;

import com.eshop.dao.GoodsDao;
import com.eshop.dao.Impl.GoodsDaoImpl;
import com.eshop.model.Goods;
import com.eshop.service.GoodsCateService;

import java.util.Comparator;
import java.util.List;

public class GoodsCateServiceImpl implements GoodsCateService {
    GoodsDao goodsDao = new GoodsDaoImpl();

    @Override
    public List<Goods> getGoodsListByCateId(int Id) {
        return goodsDao.queryGoodsByCateId(Id);
    }

    @Override
    public List<Goods> getGoodsListByCateIdSort(int Id,String sort) {
        switch (sort) {
            case "1":
                return goodsDao.queryGoodsByCateIdSort(Id, Comparator.comparingDouble(Goods::getGoods_discount));
            case "2":
                return goodsDao.queryGoodsByCateIdSort(Id, Comparator.comparingDouble(Goods::getGoods_discount).reversed());
            case "3":
                return goodsDao.queryGoodsByCateIdSort(Id, Comparator.comparingInt(Goods::getGoods_sales).reversed());
            case "4":
                return goodsDao.queryGoodsByCateIdSort(Id, Comparator.comparingInt(Goods::getGoods_sales));
        }
        return null;
    }

    @Override
    public List<Goods> fuzzyEnquiry(String name) {
        return goodsDao.fuzzyEnquiry(name);
    }

    @Override
    public List<Goods> fuzzyEnquirySort(String name, String sort) {
        switch (sort) {
            case "1":
                return goodsDao.fuzzyEnquirySort(name, Comparator.comparingDouble(Goods::getGoods_discount));
            case "2":
                return goodsDao.fuzzyEnquirySort(name, Comparator.comparingDouble(Goods::getGoods_discount).reversed());
            case "3":
                return goodsDao.fuzzyEnquirySort(name, Comparator.comparingInt(Goods::getGoods_sales).reversed());
            case "4":
                return goodsDao.fuzzyEnquirySort(name, Comparator.comparingInt(Goods::getGoods_sales));
        }
        return null;
    }
}
